package com.eiletxie.springcloud.webfluxtest;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.function.Function;

public interface GH {
    default <T> Mono<T> run(Mono<T> toRun) {
        return this.run(toRun, (throwable) -> {
            throw new RuntimeException("No fallback available.", throwable);
        });
    }

    <T> Mono<T> run(Mono<T> toRun, Function<Throwable, Mono<T>> fallback);

    default <T> Flux<T> run(Flux<T> toRun) {
        return this.run(toRun, (throwable) -> {
            throw new RuntimeException("No fallback available.", throwable);
        });
    }

    <T> Flux<T> run(Flux<T> toRun, Function<Throwable, Flux<T>> fallback);
}

